//
//  FailView.m
//  NewGame
//
//  Created by wwj on 15/10/23.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "FailView.h"
#import "SoundTool.h"

@interface FailView ()
@property (weak, nonatomic) IBOutlet UIView *boyAndWord;
@property (weak, nonatomic) IBOutlet UIView *prison;
@property (weak, nonatomic) IBOutlet UILabel *ownerScore;
@property (weak, nonatomic) IBOutlet UILabel *condition;
@end

@implementation FailView

+(instancetype)failView{
    return [[[NSBundle mainBundle] loadNibNamed:@"FailView" owner:nil options:nil] firstObject];
}

-(void)begin{
    _boyAndWord.transform = CGAffineTransformMakeTranslation(0, CGRectGetMaxY(_boyAndWord.frame));
    _prison.transform = CGAffineTransformMakeTranslation(0, CGRectGetMaxY(_prison.frame));
    
    [UIView animateWithDuration:0.3 animations:^{
        _boyAndWord.transform = CGAffineTransformIdentity;
        [[SoundTool sharedSoundTool] playSound:kSoundFailDrop];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            _prison.transform = CGAffineTransformIdentity;
            [[SoundTool sharedSoundTool] playSound:kSoundCageDrop];
            [[SoundTool sharedSoundTool] playSound:kSoundFailShout];
        }];
    }];
}

-(void)setScore:(CGFloat)score minScore:(CGFloat)minScore{
    _ownerScore.text = [NSString stringWithFormat:@"您的得分：%.f分", score];
    _condition.text = [NSString stringWithFormat:@"闯关要求：> %.f分", minScore];
}

- (IBAction)retry {
    // 1.关闭当前控制器
    UINavigationController *nav =  (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    [nav popViewControllerAnimated:YES];
    
    // 2.通知关卡界面重新开始游戏
    [[NSNotificationCenter defaultCenter] postNotificationName:@"restartGame" object:nil];
}

- (IBAction)home {
    UINavigationController *nav =  (UINavigationController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    [nav popToRootViewControllerAnimated:YES];
}


@end
